/**
 *      插件整合____更新时间_____2014.4.18 ( time: 10.18 PM )
 *
 *      最新更新的是社区代表端代码  用户端未整合
 *
 *      最后整合: iOS已经整合
 *
 *      整合内容: 解决地图定位崩溃问题
 */

/**  发送短信插件
 *
 *   number:     短信接收号码
 *   content:    短信内容
 */

function sendSMS(number, content, success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "ContactPlugin", "sendMessage", [number, content]);
    }
    
    // Android
    else if(brows().android) {
        return cordova.exec(success_callback, failed_callback, "MessagePlugin", "sendMessageEvent", [number, content]);
    }
}


/**  拨打电话插件
 *
 *  number:     拨通电话号码
 */
function getCall(number, success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "ContactPlugin", "getCall", [number]);
    }
    
    // Android
    else if(brows().android) {
        return  cordova.exec(success_callback, failed_callback, "PhonePlugin", "callPhoneEvent", [number]);
    }
}


/**  拍照
 *
 *  返回值:    图片的地址URL    (string)
 */
function getPhotoFromCamera(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "PhotoPlugin", "photoCamera", []);
    }
    
    // Android
    else if(brows().android) {
        return  cordova.exec(success_callback, failed_callback, "PhotoPlugin", "photoCamera", []);
    }
}


/**  相册 
 *
 *  参数:     maxNumber    多选相册最大图片数
 *
 *  返回值:   图片得地址URL
 *           如果单选照片    (string)
 *           如果多选照片    (array 数组内部内容为URL)
 */
function getPhotoFromAlbum(maxNumber, success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "PhotoPlugin", "photoLib", [maxNumber]);
    }

    // Android
    else if(brows().android) {
        return  cordova.exec(success_callback, failed_callback, "PhotoPlugin", "photoLib", [maxNumber]);
    }
}


/**  清除缓存
 *
 *   删除本地图片文件
 */
function clearCache(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
         cordova.exec(success_callback, failed_callback, "PhotoPlugin", "removePhoto", []);
    }
    
    // Android
    else if(brows().android) {
        return  cordova.exec(success_callback, failed_callback, "PhotoPlugin", "removePhoto", []);
    }
}


/** 上传图片
 *  
 *  参数:     uploadURL: 上传图片的链接
 *           filePath:  本地文件的路径     (类型数组)
 *           basePath:  存在服务器上的图片路径
 *           height:    缩略图的高
 *           width:     缩略图的宽
 *
 *  返回值:   Json 
 *           内有2个数组, 成功上传的本地图片路径, 失败上传的本地路径 
 */
function uploadImage(uploadURL, filePath, basePath, width, height, success_callback, failed_callback) {
    // iOS
    
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "PhotoPlugin", "uploadImage", [uploadURL, filePath, basePath, width, height]);
    }
    
    // Android
    else if(brows().android) {
        return  cordova.exec(success_callback, failed_callback, "UpLoadImagePlugin", "uploadimage", [uploadURL, filePath, basePath, width, height]);
    }
}


/**  推出地图界面 (社区灵通专用)
 *  
 *   参数:     locationArray:  [纬度, 精度]
 *                json     :   首次登入地图的所有大头针的信息
 *
 *   返回值:   成功回调 返回Json
*
 *   Json 格式:
 *
 *   {
        address = "\U4e1c\U57ce\U5b89\U5b9a\U95e8\U5185\U5927\U8857\U5206\U53f8\U5385\U80e1\U540c17\U53f7";
        id = 102241;
        latitude = "39.951";
        longitude = "116.412";
        name = "\U4eac\U9999\U798f\U82d1";
        "publicly_visible" = 0;
        range = "0.6415715021253769";
     }
 */
function pushMapView( locationArray, json, success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "MapPlugin", "pushMapView", [locationArray, json]);
    }
    
    // Android
    else if(brows().android) {
        return  cordova.exec(success_callback, failed_callback, "LocationMapPlugin", "locationmap", [locationArray, json]);
    }
}


/**  定位 (社区灵通)
 *  
 *  函数描述: 当定位成功时, 调用success_callback
 *           返回参数:   locationArray [纬度, 精度]
 *           返回类型: 数组
 *
 *           当定位失败时, 调用failed_callback
 *
 */
function getLocation(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "MapPlugin", "getCurrentLocation", []);
    }
    
    // Android
    else if(brows().android) {
       return cordova.exec(success_callback, failed_callback,"GetLocationPlugin","getlocation","");
    }
}

/** 定位(社区代表)
 *
 *  函数描述: 当定位成功时, 调用success_callback 
                返回参数: locationInfo [纬度, 精度,  地址信息]   
                返回类型: 数组
                注意事项: 当获取地址信息失败的时候, 地址信息内容为:"获取当前位置失败"
 *               
 *           当定位失败时, 调用failed_callback
 *
 *  返回值:   
 *
 *
 *  本插件定位的之后又跟服务器请求了一次数据信息, 如果只要经纬度最好用上边的插件
 */
function getLocationInfo(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "MapPlugin", "getCurrentLocationInfo", []);
    }
    
    // Android
    else if(brows().android) {
       return cordova.exec(success_callback, failed_callback,"GetLocationPlugin","getlocation","");
    }
}

/**  版本升级
 *   
 */
function updataApp(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        cordova.exec(success_callback, failed_callback, "VersionCheckPlugin", "checkAppVersion", []);
    }
    
    // Android
    else if(brows().android) {
       
    }
}


//=======================     下面的插件      =============================

/**  二维码
 *
 */
function getBarcodeScanner(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {
        
    }
    
    // Android
    else if(brows().android) {
       
    }
}



/**  录音
 *
 */
function getAudio(success_callback, failed_callback) {
    // iOS
    if(brows().iphone) {

    }
    
    // Android
    else if(brows().android) {
        
    }
}






/*===================   help code    ===================================*/

/**
 *  判断当前设备是 iOS || Andriod
 */
function brows(){
    var brows = navigator.userAgent;
    return {
    iphone: brows.indexOf('Mac') > -1,
    android: brows.indexOf('Android') > -1
    }
}


/**
 *  测试专用
 */
 function test(obj) {
    alert("测试专用, 调用成功");
    alert("内容为: " + obj);
 }



